<template>
  <div class="login-page">
    <img src="../assets/StatusBar/Light.png" alt="">
    <div class="logo">
      <img src="../assets/icon/logo.svg" alt="">
      <span>· IT资讯</span>
    </div>
    <h2>欢迎登录</h2>
    <van-form @submit="onSubmit">
      <van-field @blur="handleMobile"
        v-model="mobile"
        name="mobile"
        placeholder="请输入手机号"
      />
      <van-field @blur="handleCode"
        v-model="code"
        type="password"
        name="code"
        placeholder="请输入密码"
      />
      <div style="margin: 16px">
        <van-button block type="info" native-type="submit"
          >登录</van-button
        >
      </div>
    </van-form>
    <img class="bottom" src="../assets/VirtualNavigation/Light.png" alt="">
  </div>
</template>

<script>
import { login } from '@/api/user'
import { setToken } from '@/utils/storage'
export default {
  name: 'login-page',
  data () {
    return {
      mobile: '',
      code: ''
    }
  },
  methods: {
    async onSubmit (values) {
      this.$toast.loading({
        message: '登录中',
        forbidClick: true,
        loadingType: 'spinner'
      })
      const res = await login(values)
      setToken(res.data.token)
      this.$toast.success('登录成功')
      this.$router.push('/')
    },
    handleMobile () {
      if (this.mobile !== '13888888888') {
        this.$toast('请填写正确的手机号')
      }
    },
    handleCode () {
      if (this.code !== '246810') {
        this.$toast('请填写正确的密码')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login-page{
  background-image: url(../assets/icon/bg@2x.png);
  .logo{
    height: 44px;
    line-height: 44px;
    img{
      margin-left: 14px;
      margin-bottom: -8px;
    }
    span{
      color: #1D2129;
      font-size: 18px;
    }
  }
  h2{
    margin: 60px 0 60px 24px;
  }
  .bottom {
    position: fixed;
    bottom: 0;
  }
}
</style>
